﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace MyVocationSpace
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
            if (Session["UserID"] == null)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string encriptPassword = BAL.Encryption.Encript(txtOldPass.Text, "&%#@?,:*");
            string encriptNewPassword = BAL.Encryption.Encript(txtNewPass.Text, "&%#@?,:*");

            string strCandidateId = BAL.Users.ChangePassword(Convert.ToInt32(Session["UserID"]), encriptPassword, encriptNewPassword);

            if (strCandidateId == "-1")
            {
                idSpanMsg.Style.Add("display", "block");
                idSpanMsg.InnerHtml = "Sorry!!  Password you entered is incorrect";

            }

            else
            {
                //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "changeCSSClass", "<script type=\"text/javascript\">$('#idSpanMsg').addClass('spanMsgs');</script>", true);
                idSpanMsg.Style.Add("display", "block");
                idSpanMsg.InnerHtml = "Your Password is Changed Successfully...";
                Clear();
            }
        }
        public void Clear()
        {
            txtOldPass.Text = "";
            txtNewPass.Text = "";
            txtConfirmPassword.Text = "";
        }
    }
}